#include<iostream>
#include<cstdio>

using namespace std;


typedef long long ll;
int main()
{
    ll n, m;
    scanf("%ld %ld", &n, &m);
    ll arr[n][m];
    ll* Shang = new ll[n]{ 0 };
    ll* Sle = new ll[m]{ 0 };
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < m; j++)
        {
            scanf("%ld", &arr[i][j]);
            Shang[i] += arr[i][j];
            Sle[j] += arr[i][j];
        }
    }



    ll ret[n][m];
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < m; j++)
        {
            ret[i][j] = Shang[i] + Sle[j] - arr[i][j];
            printf("%ld ", ret[i][j]);
        }
        printf("\n");
    }







}